package LeetCode刷题.暑假刷的算法;

import java.util.Arrays;

/**
 * @program: Java_Study
 * @author: Xiaofan
 * @createTime: 2021-09-07 19:45
 * @description: Functions of this class is
 **/
public class 数组中最大数对和最小值 {
    public static void main(String args[]){
        int nums[]={4,1,5,1,2,5,1,5,5,4};
        System.out.println(minPairSum(nums));
    }
    public static int minPairSum(int[] nums) {
//        Arrays.sort(nums);
//        int ans=0;
//        int i=0;
//        int j=nums.length-1;
//        int len=nums.length>>1;
//        while (i<len){
//            ans=Math.max(ans,nums[i++]+nums[j--]);
//        }
        Arrays.sort(nums);
        int ans=0;
        int k=0;
        while (k<nums.length>>1){
            ans=Math.max(ans,nums[k]+nums[nums.length-1-k]);
            k++;
        }
        return ans;
    }
}